import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../app/modules/base_tab_bar_module/base_tab_bar_controller.dart';

class BaseTabBarPage extends StatelessWidget {
  final controller = Get.find<BaseTabBarController>();
  BaseTabBarPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(title: Text('BaseTabBar'.tr)),
      bottomNavigationBar: _buildBottomNavigationBar(),
      body: _buildPageView(),
    );
  }

  Widget _buildBottomNavigationBar() {
    return Obx(
      () {
        if (controller.tabPageBodies.isEmpty) {
          return Container();
        } else {
          return BottomNavigationBar(
            items: controller.bottomTabs,
            currentIndex: controller.currentPage,
            type: BottomNavigationBarType.fixed,
            // fixedColor: Colors.red,
            selectedFontSize: 10,
            unselectedFontSize: 10,
            onTap: (int index) => controller.switchBottomTabBar(index),
          );
        }
      },
    );
  }

  /// 内容页
  Widget _buildPageView() {
    return PageView(
      //禁止滑动
      physics: const NeverScrollableScrollPhysics(),
      controller: controller.pageController,
      onPageChanged: (index) => controller.onPageChanged(index),
      children: controller.tabPageBodies,
    );
  }
}
